#include "ThreadQueue.hh"

ThreadQueue::ThreadQueue(size_t thread_size, size_t capacity)
    : _thread_size(thread_size)
    , _task_queue(capacity)
    , _is_exit(false){

}

ThreadQueue::~ThreadQueue(){

}

void ThreadQueue::Add_task(Task &task){
    if(task){
        _task_queue.push(task);
    }else{
        throw "task is nullptr";
    }
}


ThreadQueue::Task ThreadQueue::Get_task(){
    return _task_queue.pop();
}

void ThreadQueue::Do_task(){
    while(!_is_exit){
        Task task = Get_task();
        if(task){
            // task();
        }
    }

}

void ThreadQueue::Start(){
    for (size_t i = 0; i < _thread_size; i++){
        _pool.push_back(unique_ptr<thread>(new thread(&ThreadQueue::Do_task, this)));
    }
}

void ThreadQueue::Stop(){

}